﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCH.DAO;
using CCH.Entity;

public partial class _20_2004 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //取回功能編號
        string sfu_type = Request.QueryString["type"];
        int sfu_no = new sysfunctionDAO().Get_pathNO(2004, sfu_type);
        ((MasterPage)this.Master).Create_menu(sfu_no);

        if (!this.IsPostBack)
        {
            this.ObjectDataSource1.SelectParameters["alb_type"].DefaultValue = sfu_type;
            this.ListView1.DataBind();
        }

        //判斷來自JS 使用_doPostBack(updatePanel,"") 的情況
        if (Request["__EVENTTARGET"] == this.UpdatePanel1.ClientID && String.IsNullOrEmpty(Request["__EVENTARGUMENT"]))
        {
            this.ObjectDataSource1.SelectParameters["alb_type"].DefaultValue = sfu_type;
            this.ListView1.DataBind();
        }
    }

    protected String Get_url(object alb_no)
    {
        return string.Format("2004-1.aspx?mode=edit&ID={0}&type={1}&modal=true&TB_iframe=true&width=800&height=320", alb_no.ToString(), Request["type"]);
    }

    protected String Get_url_new()
    {
        return string.Format("2004-1.aspx?mode=new&type={0}&modal=true&TB_iframe=true&width=800&height=320", Request["type"]);
    }


    protected void btn_del_Click(object sender, EventArgs e)
    {
        albumDAO dao = new albumDAO();
        int peo_uid = new SessionObject().SessionUserID;

        foreach (var item in this.ListView1.Items)
        {
            album d = (album)this.ListView1.DataKeys[item.DataItemIndex].Value;

            CheckBox cb = (CheckBox)item.FindControl("CheckBox1");

            if (cb.Checked)
            {
                dao.Delete_album(d.alb_no, peo_uid);
            }
        }

        this.ObjectDataSource1.SelectParameters["alb_type"].DefaultValue = Request.QueryString["type"];
        this.ListView1.DataBind();

    }
}